<?php
use \Workerman\Autoloader;

require_once __DIR__ . '/../../../../../Workerman/Autoloader.php';
require_once __DIR__.'/../../../Config/Const.php';
Autoloader::setRootPath(__DIR__.'/../../..');

$page_groupId = GROUP_TREE_MNG;
$page_pageId = PAG_SPECIES_ADD;
require "../framepages/moudle_base.php";

$gg_list = \Data\Tree_gg_DAO::getList();

$result = 'normal';
$mode = $_POST['mode'];
if ($mode == 'species_dd') {
    $species_name = $_POST['species_name'];
    // 是否已添加过同名称花木
    $species_record = \Data\Tree_species_DAO::getRecordByName($species_name);
    if ($species_record) {
        $err_msg = 'err_same_name';
    } else {
        $gg = $_POST['gg'];

        $species_record = new \Data\Tree_species(array());
        $species_record->setSPECIES_NAME($species_name);

        $species_record->setGG($gg);
        $species_id = \Data\Tree_species_DAO::insert($species_record);

        $result = 'succ_add';
    }

}

?>
<div class="main-content">
    <form action="" method="post">
        <input type="hidden" name="mode" id="mode" value='species_dd'>

        <table>
            <tr>
                <td width="12%">品种名称:<td>
                <td width="25%"><input type="text" id="species_name" name="species_name" placeholder="例如：白蜡" ><td>
                <td width="6%">规格类型:</td>
                <td>
                    <select id='gg' name='gg'>
                        <?php
                        foreach ($gg_list as $gg_record) {
                            $gg_id = $gg_record->getGG_ID();
                            $gg_name = $gg_record->getGG_NAME();
                            $gg_dw = $gg_record->getGG_DW();
                            $gg = $gg_name." (".$gg_dw.")";

                            echo "
                            <option id='gg' name='gg' value='$gg_id'> $gg </option>                  
                            ";
                        }
                        ?>
                    </select>
                </td>
                <td><input type="submit" class="btn btn-danger" value="提交"></td>
            </tr>
            <tr>

            </tr>
        </table>

        <div id="group_array"></div>
    </form>


</div>
</div>
<script src="../lib/bootstrap/js/bootstrap.js"></script>
<script>
    function init() {
        var err_msg = "<?php echo $err_msg ?>";
        if (err_msg == 'err_same_name') {
            aler("添加失败，已存在同名称花木");
        }

        var result = "<?php echo $result ?>";
        if (result == 'succ_add') {
            alert('添加成功');
        }
    }


</script>
</body>
</html>